#!/usr/bin/env bash
tag='latest'
args=()

while [[ -n "$1" ]]; do
    if [[ "$1" == '--update' ]]; then
        # Update Docker image
        update='1'
    else
        args+=("$1")
    fi

    shift 1
done

if [[ -n "${update}" ]]; then
    docker pull "synesthesiam/voice2json:${tag}"
fi

docker run -i \
       --init \
       -v "${HOME}:${HOME}" \
       -v "/dev/shm/:/dev/shm/" \
       -w "$(pwd)" \
       -e "HOME=${HOME}" \
       --user "$(id -u):$(id -g)" \
       "synesthesiam/voice2json:${tag}" "${args[@]}"
